package com.boesch.electroOffice.dataaccess.mapper;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.boesch.electroOffice.model.electroOffice.Charge;
import com.boesch.electroOffice.utils.DateUtils;

/**
 * This class mappes the rows from database to a Charge object.
 * 
 * @author Ralph Koster
 *
 */
public class ChargeMapper implements RowMapper<Charge>, Serializable {

	private static final long serialVersionUID = 9140891055376855908L;

	/**
	 * Mapps all rows from database to a Charge object.
	 * 
	 * @see org.springframework.jdbc.core.RowMapper
	 */
	public Charge mapRow(ResultSet rs, int rowNum) throws SQLException {
		Charge charge = new Charge();
		charge.setId(rs.getInt("Id_pk"));
		charge.setValue(rs.getDouble("Value"));
		charge.setCreatedBy(rs.getString("Createdby"));
		charge.setCreatedAt(DateUtils.convertTimestampToLocalDateTime(rs.getTimestamp("Createdat")));
		charge.setModifiedBy(rs.getString("Modifiedby"));
		charge.setModifiedAt(DateUtils.convertTimestampToLocalDateTime(rs.getTimestamp("Modifiedat")));
		charge.setVersion(rs.getInt("Version"));

		return charge;
	}
}
